package com.liang.response.utils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * class工具类
 *
 * @author liangyehao
 * @date 2021/04/29
 */
public class ClazzUtils {
    public static Field[] getAllFields(Object o){
        Class<?> c= o.getClass();
        List<Field> fieldList = new ArrayList<>();
        while (c!= null){
            fieldList.addAll(new ArrayList<>(Arrays.asList(c.getDeclaredFields())));
            c= c.getSuperclass();
        }
        Field[] fields = new Field[fieldList.size()];
        fieldList.toArray(fields);
        return fields;
    }

}
